package com.sunny.ynhz.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sunny.ynhz.R;
import com.sunny.ynhz.bean.OneRiverOneRuleBean;
import com.sunny.ynhz.ui.daily.specialcolumn.RankNaviActivity;
import com.sunny.ynhz.utils.TypeAndStatusUtil;

import java.util.List;

/**
 * Created by huhuan123 on 2018/6/3.
 */

public class OneRiverOneRuleAdapter extends BaseAdapter {
    int[] rankImg = {R.mipmap.ic_gj, R.mipmap.ic_yj, R.mipmap.ic_jj};
    int[] rankbg = {R.mipmap.bg_gj, R.mipmap.bg_yj, R.mipmap.bg_jj, R.drawable.bg_ysyz_text};
    Activity context;
    List<OneRiverOneRuleBean.ListBean> mlist;
    private int type;

    public OneRiverOneRuleAdapter(Context context, List<OneRiverOneRuleBean.ListBean> mlist, int type) {
        this.context = (Activity) context;
        this.mlist = mlist;
        this.type = type;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View randContent = LayoutInflater.from(context).inflate(R.layout.item_rank_msg, null);
        View randView = randContent.findViewById(R.id.ll_bg_content);
        LinearLayout layout = randView.findViewById(R.id.ll_content);
        RelativeLayout ll_rank = (RelativeLayout) layout.getChildAt(0);
        ImageView img_rank = (ImageView) ll_rank.getChildAt(0);
        TextView tv_rank_num = (TextView) ll_rank.getChildAt(1);
        TextView tv_userName = (TextView) layout.getChildAt(1);
        TextView tv_lake = (TextView) layout.getChildAt(2);
        TextView tv_outofline = (TextView) layout.getChildAt(3);
        OneRiverOneRuleBean.ListBean listBean1 = mlist.get(i);
        int rankNum = listBean1.getRankNum();
        OneRiverOneRuleBean.ListBean listBean = mlist.get(i);
        String progressBar = listBean.getProgressBar();
        String content = listBean.getContent();
        String name = listBean.getName();
        String river;
        if (type == 0) {
            river = listBean.getRiver();
        } else {
            river = listBean.getRiverName();
        }
        tv_userName.setText(name);
        tv_lake.setText(river);
        tv_outofline.setText(TypeAndStatusUtil.getProblemValue(listBean.getType()));

        if (rankNum == 1) {
            randView.setBackgroundResource(rankbg[0]);
            img_rank.setImageResource(rankImg[0]);
            tv_userName.setTextColor(Color.WHITE);
            tv_lake.setTextColor(Color.WHITE);
            tv_outofline.setTextColor(Color.WHITE);
            tv_rank_num.setVisibility(View.GONE);
        } else if (rankNum == 2) {
            randView.setBackgroundResource(rankbg[1]);
            img_rank.setImageResource(rankImg[1]);
            tv_userName.setTextColor(Color.WHITE);
            tv_lake.setTextColor(Color.WHITE);
            tv_outofline.setTextColor(Color.WHITE);
            tv_rank_num.setVisibility(View.GONE);

        } else if (rankNum == 3) {
            randView.setBackgroundResource(rankbg[2]);
            img_rank.setImageResource(rankImg[2]);
            tv_userName.setTextColor(Color.WHITE);
            tv_lake.setTextColor(Color.WHITE);
            tv_outofline.setTextColor(Color.WHITE);
            tv_rank_num.setVisibility(View.GONE);
        } else {
            randView.setBackgroundResource(rankbg[3]);
            tv_userName.setTextColor(Color.parseColor("#666666"));
            tv_lake.setTextColor(Color.parseColor("#666666"));
            tv_outofline.setTextColor(Color.parseColor("#666666"));
            tv_rank_num.setVisibility(View.VISIBLE);
            tv_rank_num.setText(listBean.getRankNum() + "");
        }
        return randContent;
    }
}
